<template>
  <login v-if="$route.name === 'Login'"></login>
  <a-config-provider prefixCls="cns" v-else>
    <section id="cns-main-app">
      <section class="cns-app-header">
        <AppHeader />
      </section>
      <section class="cns-menu-wrapper" :style="menuStyle">
        <div class="menu-container">
          <main-menu :collapsed="collapsed" />
        </div>
        <div class="button-container">
          <a-button type="primary" @click="toggleCollapsed">
            <a-icon :type="collapsed ? 'menu-unfold' : 'menu-fold'" />
          </a-button>
        </div>
      </section>
      <section class="cns-frame-shell" :style="frameStyle">
        <section class="cns-page-exp">
          <app-page-exp />
        </section>
        <section class="cns-frame-wrapper">
          <!-- 主应用渲染区，用于挂载主应用路由触发的组件 -->
          <router-view v-show="$route.name" />

          <!-- 子应用渲染区，用于挂载子应用节点 -->
          <section v-show="!$route.name" id="frame"></section>
        </section>
      </section>
    </section>
  </a-config-provider>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import MainMenu from "@/components/menu/index.vue";
import Login from "@/pages/login/index.vue";
import AppHeader from "@/components/app-header/app-header.vue";
import AppPageExp from "./components/app-page-exp/app-page-exp.vue";

@Component({
  components: {
    MainMenu,
    Login,
    AppHeader,
    AppPageExp,
  },
})
export default class App extends Vue {
  /**
   * 是否收缩菜单
   */
  collapsed: boolean = false;

  /**
   * 菜单容器样式
   */
  get menuStyle() {
    return {
      width: this.collapsed ? "80px" : "200px",
    };
  }

  /**
   * 容器样式
   */
  get frameStyle() {
    return {
      width: this.collapsed ? "calc(100vw - 80px)" : "calc(100vw - 200px)",
      left: this.collapsed ? "80px" : "200px",
    };
  }

  /**
   * 处理菜单收缩
   *
   */
  public toggleCollapsed() {
    this.collapsed = !this.collapsed;
    const childContainerLoading = document.getElementById("child-container-loading");
    if(childContainerLoading){
      childContainerLoading.style.left = this.collapsed ? "80px" : "200px";
    }
  }
}
</script>

<style lang="less" scoped>
#cns-main-app {
  height: 100%;
  position: relative;
  .cns-app-header {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    z-index: 2000;
  }
  .cns-menu-wrapper {
    position: fixed;
    left: 0;
    top: 48px;
    bottom: 0;
    > .menu-container {
      height: calc(100% - 48px);
      width: 100%;
      overflow-x: hidden;
      overflow-y: auto;
    }
    > .button-container {
      height: 48px;
      width: 100%;
      color: rgba(255, 255, 255, 0.65);
      background: #001529;
      display: flex;
      justify-content: end;
      padding: 8px 16px;
    }
  }
  .cns-frame-shell {
    position: absolute;
    top: 48px;
    height: calc(100vh - 48px);
    overflow: hidden;
    .cns-page-exp {
      width: 100%;
      height: 50px;
      margin: 3px 0;
    }
    .cns-frame-wrapper {
      position: relative;
      height: calc(100% - 50px);
      width: 100%;
      overflow: hidden;
    }
  }
}

#cns-frame {
  width: 100%;
  height: 100%;
  > :first-child {
    height: 100%;
  }
}
#frame {
  height: 100%;
  overflow: hidden;
}
</style>
